package net.sudot.chess.business.wechat.handler;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用户在微信发送的消息处理
 *
 * @author tangjialin on 2017-05-04 0004.
 */
@Component
public class MsgHandler extends AbstractHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
//		// 当用户输入关键词如“你好”，“客服”等，并且有客服在线时，把消息转发给在线客服
//		WechatApiService wechatApiService = (WechatApiService) wxMpService;
//		if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
//				&& wechatApiService.hasKefuOnline()) {
//			return WxMpXmlOutMessage
//					.TRANSFER_CUSTOMER_SERVICE().fromUser(wxMessage.getToUser())
//					.toUser(wxMessage.getFromUser()).build();
//		}

        String content = "亲爱的用户,如您需要帮助,可点击右下角[联系客服]";
        return WxMpXmlOutMessage.TEXT().content(content)
                .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
                .build();
    }

}
